package org.dslmagic.demo;

import static org.dslmagic.DataManipulationDsl.*;

import java.util.Arrays;
import java.util.Comparator;

import org.dslmagic.dsl.Dsl;

public class Demo {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		$interpreter(MyInterpreter.class);

		println(like("Nikola", "iko")).run();

		Person person = new Person("Nikolce", 26);

		person = $(person).def(Runnable.class,
				println(call("lte", get($, "age"), 19)));

		Runnable runn = (Runnable) person;
		runn.run();

		person = $(person).def(Runnable.class, println(get($, "name")));
		runn = (Runnable) person;
		runn.run();

		Person person2 = new Person("Nikola", 29);
		$(person2).as(Runnable.class, println("Person running!")).run();

		Runnable test = $(Runnable.class).def(println("Just running!"));
		test.run();

		Dsl isAdult = gte(get($, "age"), 18);
		Dsl isNikolche = eq(get($, "name"), "Nikolche");
		Dsl similar = and(isAdult, isNikolche);
		
		println(similar).run($(person));

		String[] words = { "aaa", "bb", "cccc", "d", "eee" };

		Arrays.sort(words, $(Comparator.class).def("compare", compare(size($))));
		print(words);
		
		Thread t = new Thread($(Runnable.class).def(println("In the thread!")));
		t.start();

		words = (String[]) filter(gte(size($), 3), $).run($(words));
		print(words);

		Person dummy = new Person("Iljo", 2);
		dummy = $(dummy).def("getName", println("Mock name"));
		System.out.println(dummy.getName());
	}

	private static void print(Object[] words) {
		System.out.println(Arrays.toString(words));
	}

}
